/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package back;

import core.SchoolMat;
import dao.ISchoolMat;
import java.io.Serializable;
import java.util.*;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Lukin
 */
@ManagedBean(name = "year")
@SessionScoped
public class YearPickerBean implements Serializable {
    
    private int year;

    private List<Integer> list;
    
    @EJB
    ISchoolMat schoolmat;
    

    public YearPickerBean() {
    }
        
    @PostConstruct
    public void init() {
        List<SchoolMat> mats = schoolmat.findAllSchoolMats();
        Set<Integer> years = new HashSet<Integer>();
        for (SchoolMat m : mats){
            years.add(m.getYear());
        }
        
        list = new ArrayList<Integer>(years);
    }

    public void setList(List<Integer> list) {
        this.list = list;
    }

    public List<Integer> getList() {
        return list;
    }
    
    public int getYear() {
        return this.year;
    }

    public void setYear(int y) {
        this.year = y;
    }
    
    public String pickYear(int year){
        this.year = year;
        
        return "SchoolMatSubject?faces-redirect=true";
    }
    
   
    
}
